<?php
declare (strict_types = 1);

namespace app\middleware;

use app\jwt\Jwt;
use think\Exception;

class CheckToken
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $token=$_SERVER["HTTP_TOKEN"];
//        dd($token);
        try {
           $user_id=Jwt::verifyJwt($token);
           $request->user_id=$user_id;
        }catch (Exception $exception){
            return json(['token获取失败']);
        }
        return $next($request);
    }

}
